#include <iostream>
#include <cassert>
#include <set>
#include <cstdlib>
#include <fstream>
#include <utility>

using namespace std;

typedef unsigned int uint;

static const int small = 4;
static const uint small_max = 1 << small;

template<int bits>
struct vanEmdeBoasTree
{
    vanEmdeBoasTree(uint a)
    {
        min_ = max_ = a;
        children_ = new vanEmdeBoasTree<bits / 2>*[1 << (bits / 2)];
        for (size_t i = 0; i < (1 << (bits / 2)); i++)
            children_[i] = NULL;
        aux_ = NULL;
    };
    
    uint min_, max_;
    vanEmdeBoasTree<bits / 2> **children_;
    vanEmdeBoasTree<bits / 2> *aux_;
    
    ~vanEmdeBoasTree()
    {
        delete[] children_;
    }
};

template<>
struct vanEmdeBoasTree<small>
{
    vanEmdeBoasTree(uint a)
    {
        for (uint i = 0; i < small_max; i++)
            has[i] = false;
        has[a] = true;
    }

    bool has[small_max];
};

template<int bits>
void insert(vanEmdeBoasTree<bits> *&tree, uint a);
    
template<int bits>
void erase(vanEmdeBoasTree<bits> *&tree, uint a);
    
template<int bits>
bool find(vanEmdeBoasTree<bits> *&tree, uint a);
    
template<int bits>
pair<bool, uint> lower_bound(vanEmdeBoasTree<bits> *&tree, uint);

void insert(vanEmdeBoasTree<small> *&tree, uint a);
void erase(vanEmdeBoasTree<small> *&tree, uint a);
bool find(vanEmdeBoasTree<small> *&tree, uint a);
uint min(vanEmdeBoasTree<small> *&tree);
uint max(vanEmdeBoasTree<small> *&tree);
pair<bool, uint> lower_bound(vanEmdeBoasTree<small> *&tree, uint);

void init(vanEmdeBoasTree<small> *&tree, uint);
void clear(vanEmdeBoasTree<small> *&tree);
bool empty(vanEmdeBoasTree<small> *&tree);

template<int bits>
void init(vanEmdeBoasTree<bits> *&tree, uint);

template<int bits>
void clear(vanEmdeBoasTree<bits> *&tree);

template<int bits>
bool empty(vanEmdeBoasTree<bits> *&tree);

int main()
{
    freopen("fastset.in", "r", stdin);
    freopen("fastset.out", "w", stdout);
    vanEmdeBoasTree<32> *tree = NULL;
    set<uint> tree2;
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        char c;
        uint x;
		scanf(" %c%u", &c, &x);
		switch(c)
		{
			case '+':
				insert(tree, x);
				break;
			case '-':
				erase(tree, x);
				break;
			case '?':
                pair<bool, uint> ans = lower_bound(tree, x);
				if (!ans.first)
					printf("-1\n");
				else
					printf("%u\n", ans.second);
        }
    }
}

void insert(vanEmdeBoasTree<small> *&tree, uint a)
{
    //~ assert(0 <= a && a <= 1);
    if (empty(tree))
    {
        init(tree, a);
    }
    else
    {
        tree->has[a] = true;
    }
}

void erase(vanEmdeBoasTree<small> *&tree, uint a)
{
    //~ assert(0 <= a && a <= 1);
    if (empty(tree))
        return;
    tree->has[a] = false;
}

bool find(vanEmdeBoasTree<small> *&tree, uint a)
{
    //~ assert(0 <= a && a <= 1);
    if (empty(tree))
        return false;
    return tree->has[a];
}

uint min(vanEmdeBoasTree<small> *&tree)
{
    //~ assert(tree != NULL);
    for (uint i = 0; i < small_max; i++)
        if (tree->has[i])
            return i;
    assert(false);
}

uint max(vanEmdeBoasTree<small> *&tree)
{
    //~ assert(tree != NULL);
    for (uint i = small_max - 1; i >= 0; i--)
        if (tree->has[i])
            return i;
    assert(false);
}

template<int bits>
uint min(vanEmdeBoasTree<bits> *&tree)
{
    //~ assert(tree != NULL);
    return tree->min_;
}

template<int bits>
uint max(vanEmdeBoasTree<bits> *&tree)
{
    //~ assert(tree != NULL);
    return tree->max_;
}

template<int bits>
void insert(vanEmdeBoasTree<bits> *&tree, uint a)
{
    if (empty(tree)) 
        init(tree, a);
    else if (tree->min_ == tree->max_)
    {
        uint tmp = tree->min_;
        tree->min_ = min(tmp, a);
        tree->max_ = max(tmp, a);
    }
    else if(tree->min_ == a || tree->max_ == a)
        return;
    else 
    {
        if (a < tree->min_)
            std::swap(a, tree->min_);
        if (a > tree->max_)
            std::swap(a, tree->max_);
        uint high = a >> (bits / 2);
        uint lower = a & ( (1 << (bits / 2)) - 1);
        if (empty(tree->children_[high]))
        {
            insert(tree->aux_, high);
        }
        insert(tree->children_[high], lower);
    }
}

template<int bits>
bool find(vanEmdeBoasTree<bits> *&tree, uint a)
{
    if (empty(tree))
        return false;
    if (a == tree->min_ || a == tree->max_)
        return true;
    if (a < tree->min_ || a > tree->max_)
        return false;
    uint high = a >> (bits / 2);
    uint lower = a & ( (1 << (bits / 2)) - 1);
    return find(tree->children_[high], lower);
}

template<int bits>
void erase(vanEmdeBoasTree<bits> *&tree, uint a)
{
    if (empty(tree))
        return;
    if (a < tree->min_ || a > tree->max_)
        return;
    if (tree->min_ == tree->max_)
    {
        if (a == tree->min_)
        {
            clear(tree);
        }
        return;
    }
    if (empty(tree->aux_))
    {
        if (a == tree->min_)
            tree->min_ = tree->max_;
        else if (a == tree->max_)
            tree->max_ = tree->min_;
        return;
    }
    if (a == tree->min_)
    {
        uint high = min(tree->aux_);
        uint lower = min(tree->children_[high]);
        uint new_min = (high << (bits / 2)) + lower;
        tree->min_ = new_min;
        erase(tree->children_[high], lower);
        if (empty(tree->children_[high]))
            erase(tree->aux_, high);
        return;
    }
    if (a == tree->max_)
    {
        uint high = max(tree->aux_);
        uint lower = max(tree->children_[high]);
        uint new_max = (high << (bits / 2)) + lower;
        tree->max_ = new_max;
        erase(tree->children_[high], lower);
        if (empty(tree->children_[high]))
            erase(tree->aux_, high);
        return;
    }
    uint high = a >> (bits / 2);
    if (empty(tree->children_[high]))
        return;
    uint lower = a & ((1 << (bits / 2)) - 1);
    erase(tree->children_[high], lower);
    if (empty(tree->children_[high]))
        erase(tree->aux_, high);
}

void init(vanEmdeBoasTree<small> *&tree, uint a)
{
    if (tree == NULL)
    {
        tree = new vanEmdeBoasTree<small>(a);
    }
    else
    {
        for (uint i = 0; i < small_max; i++)
            tree->has[i] = false;
        tree->has[a] = true;
    }
}

void clear(vanEmdeBoasTree<small> *&tree)
{
    if (tree == NULL)
        return;
    for (uint i = 0; i < small_max; i++)
        tree->has[i] = false;
}

bool empty(vanEmdeBoasTree<small> *&tree)
{
    if (tree == NULL)
        return true;
    for (uint i = 0; i < small_max; i++)
        if (tree->has[i])
            return false;
    return true;
}

template<int bits>
void init(vanEmdeBoasTree<bits> *&tree, uint a)
{
    if (tree == NULL)
        tree = new vanEmdeBoasTree<bits>(a);
    else
    {
        tree->min_ = tree->max_ = a;
    }
}

template<int bits>
void clear(vanEmdeBoasTree<bits> *&tree)
{
    if (tree == NULL)
        return;
    tree->min_ = 1;
    tree->max_ = 0;
}

template<int bits>
bool empty(vanEmdeBoasTree<bits> *&tree)
{
    if (tree == NULL)
        return true;
    return tree->min_ > tree->max_;
}

pair<bool, uint> lower_bound(vanEmdeBoasTree<small> *&tree, uint a)
{
    if (empty(tree))
        return make_pair(false, 0);
    for (uint i = a; i < small_max; i++)
        if (tree->has[i])
            return make_pair(true, i);
    return make_pair(false, 0);
}

template<int bits>
pair<bool, uint> lower_bound(vanEmdeBoasTree<bits> *&tree, uint a)
{
    if (empty(tree))
        return make_pair(false, 0);
    if (a <= tree->min_)
        return make_pair(true, tree->min_);
    if (tree->max_ < a)
        return make_pair(false, 0);
    if (empty(tree->aux_))
    {
        if (a <= tree->max_)
            return make_pair(true, tree->max_);
        return make_pair(false, 0);
    }
    uint high1 = max(tree->aux_);
    uint lower1 = max(tree->children_[high1]);
    uint ans1 = (high1 << (bits / 2)) + lower1;
    if (ans1 < a)
        return make_pair(true, tree->max_);
    uint high = a >> (bits / 2);
    uint lower = a & ((1 << (bits / 2)) - 1);
    if (empty(tree->children_[high]) || max(tree->children_[high]) < lower)
    {
        uint high2 = lower_bound(tree->aux_, high + 1).second;
        uint lower2 = min(tree->children_[high2]);
        uint ans2 = (high2 << (bits / 2)) + lower2;
        return make_pair(true, ans2);
    }
    else
    {
        uint high = a >> (bits / 2);
        uint lower2 = a & ((1 << (bits / 2)) - 1);
        uint lower = lower_bound(tree->children_[high], lower2).second;
        uint ans = (high << (bits / 2)) + lower;
        return make_pair(true, ans);
    }
}
